/*
 * Copyright (c) ShaoxiongDu <Shaoxiong.dev@aliyun.com> 2021 all Rights Reserved
 */

package zh.codegym.task.task07.task0724;

/* 
家庭人口普查
*/

public class Solution {
    public static void main(String[] args) {
        // 在此编写你的代码
        Human zufu1 = new Human("祖父1", true, 80);
        Human zufu2 = new Human("祖父2", true, 87);
        Human zumu1 = new Human("祖母1", false, 80);
        Human zumu2 = new Human("祖母1", false, 80);
        Human fuqin = new Human("父亲", true, 60, zufu1, zumu1);
        Human muqing = new Human("母亲", false, 80, zufu2, zumu2);
        Human haizi1 = new Human("孩子1", true, 20, fuqin, muqing);
        Human haizi2 = new Human("孩子2", true, 20, fuqin, muqing);
        Human haizi3 = new Human("孩子3", true, 20, fuqin, muqing);

        System.out.println(zufu1);
        System.out.println(zufu2);
        System.out.println(zumu1);
        System.out.println(zumu2);
        System.out.println(fuqin);
        System.out.println(muqing);
        System.out.println(haizi1);
        System.out.println(haizi2);
        System.out.println(haizi3);
    }

    public static class Human {
        // 在此编写你的代码
        private String name;
        private boolean sex;
        int age;
        private Human father;
        private Human mother;

        public Human(String name, boolean sex, int age) {
            this.name = name;
            this.sex = sex;
            this.age = age;
        }

        public Human(String name, boolean sex, int age, Human father, Human mother) {
            this.name = name;
            this.sex = sex;
            this.age = age;
            this.father = father;
            this.mother = mother;
        }

        @Override
        public String toString() {
            String text = "";
            text += "名字：" + this.name;
            text += "，性别：" + (this.sex ? "男" : "女");
            text += "，年龄：" + this.age;

            if (this.father != null) {
                text += "，父亲：" + this.father.name;
            }

            if (this.mother != null) {
                text += "，母亲：" + this.mother.name;
            }

            return text;
        }
    }
}